<html>
<head><meta charset="utf-8"><title>winnowing soundly · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html">winnowing soundly</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247899832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247899832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247899832">(Aug 02 2021 at 08:23)</a>:</h4>
<p>thinking a bit about marker trait stabilization and also the auto trait unsoundness.</p>
<p>in <code>candidate_should_be_dropped_in_favor_of</code> the following section is unsound <a href="https://github.com/rust-lang/rust/blob/b53a93db2d7717c3bde196cfcf5f214cc00d4937/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1489">https://github.com/rust-lang/rust/blob/b53a93db2d7717c3bde196cfcf5f214cc00d4937/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1489</a></p>
<p>if <code>other</code> does not satisfy it's region obligation we still drop <code>victim</code> which may apply even when considering regions. This causes us to incorrectly assume that a predicate does not hold, causing <a href="https://github.com/rust-lang/rust/issues/84955">#84955</a></p>



<a name="247899902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247899902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247899902">(Aug 02 2021 at 08:25)</a>:</h4>
<p>as this bug relies on the order of the candidates, the given test case doesn't actually work right now</p>



<a name="247900063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247900063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247900063">(Aug 02 2021 at 08:27)</a>:</h4>
<p>i think, can't actually reproduce that test rn <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="247908088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247908088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247908088">(Aug 02 2021 at 10:48)</a>:</h4>
<p>jup, can't trivially reproduce <a href="https://github.com/rust-lang/rust/issues/84955">#84955</a> <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="247908109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247908109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247908109">(Aug 02 2021 at 10:48)</a>:</h4>
<p>that's unfortunate <span aria-label="sparkles" class="emoji emoji-2728" role="img" title="sparkles">:sparkles:</span></p>



<a name="247910611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910611">(Aug 02 2021 at 11:28)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/144729-wg-traits/topic/winnowing.20soundly/near/247899832">said</a>:</p>
<blockquote>
<p>thinking a bit about marker trait stabilization and also the auto trait unsoundness.</p>
<p>in <code>candidate_should_be_dropped_in_favor_of</code> the following section is unsound <a href="https://github.com/rust-lang/rust/blob/b53a93db2d7717c3bde196cfcf5f214cc00d4937/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1489">https://github.com/rust-lang/rust/blob/b53a93db2d7717c3bde196cfcf5f214cc00d4937/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1489</a></p>
<p>if <code>other</code> does not satisfy it's region obligation we still drop <code>victim</code> which may apply even when considering regions. This causes us to incorrectly assume that a predicate does not hold, causing <a href="https://github.com/rust-lang/rust/issues/84955">#84955</a></p>
</blockquote>
<p>this issue should still apply though</p>



<a name="247910708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910708">(Aug 02 2021 at 11:30)</a>:</h4>
<p>even if not relevant for soundness, there is also </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(marker_trait_attr)]</span><span class="w"></span>

<span class="cp">#[marker]</span><span class="w"></span>
<span class="k">trait</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="o">&amp;'</span><span class="nb">static</span><span class="w"> </span><span class="p">(),</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="p">())</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">A</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="p">(),</span><span class="w"> </span><span class="o">&amp;'</span><span class="nb">static</span><span class="w"> </span><span class="p">())</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="247910750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910750">(Aug 02 2021 at 11:30)</a>:</h4>
<p>which fails to compile as we have the candidates in the same order when wf checking the 2 impls</p>



<a name="247910755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910755">(Aug 02 2021 at 11:30)</a>:</h4>
<p>but always prefer the first candidate</p>



<a name="247910771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910771">(Aug 02 2021 at 11:31)</a>:</h4>
<p>during winnowing, resulting in the following error</p>
<div class="codehilite"><pre><span></span><code>error[E0308]: mismatched types
 --&gt; src/lib.rs:6:10
  |
6 | impl&lt;&#39;a&gt; A for (&amp;&#39;static (), &amp;&#39;a ()) {}
  |          ^ lifetime mismatch
  |
  = note: expected trait `A`
             found trait `A`
note: the lifetime `&#39;a` as defined on the impl at 6:6...
 --&gt; src/lib.rs:6:6
  |
6 | impl&lt;&#39;a&gt; A for (&amp;&#39;static (), &amp;&#39;a ()) {}
  |      ^^
  = note: ...does not necessarily outlive the static lifetime
</code></pre></div>



<a name="247910796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910796">(Aug 02 2021 at 11:31)</a>:</h4>
<p>with the current impl this test should fail no matter how we modify candidate assembly (which we don't want)</p>



<a name="247910842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910842">(Aug 02 2021 at 11:32)</a>:</h4>
<p>I can think of 2 ways to fix this</p>



<a name="247910904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910904">(Aug 02 2021 at 11:33)</a>:</h4>
<ul>
<li>check regions during fulfill so that we always end up with 2 evaluated to ok considering regions here, actually allowing us to choose an arbitrary marker trait impl</li>
</ul>



<a name="247910998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247910998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247910998">(Aug 02 2021 at 11:34)</a>:</h4>
<ul>
<li>keep the "delayed regionck" and add some sort of "or" to our region obligations, so we "accept" both candidates and then only have to satisfy one of those during regionck</li>
</ul>



<a name="247911083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247911083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247911083">(Aug 02 2021 at 11:36)</a>:</h4>
<p>i think conceptually the first option seems cleaner but I don't know enough to say much about either approach</p>



<a name="247911189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/winnowing%20soundly/near/247911189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/winnowing.20soundly.html#247911189">(Aug 02 2021 at 11:37)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span> do you have some thoughts here? I vaguely remember some mention of removing the separate regionck entirely <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>